var TimeProvider    =   require("../util/timeProvider");
var ProtoMessage    =   require("./protoMessage");

var ReqMessage  =   function() {
    this.request    =   new ProtoMessage.Request();
    this.worker     =   undefined;
    this.promise    =   undefined;
    this.timer      =   undefined;
    this.adapter    =   undefined;
    this.property   =   undefined;
    this.costTime   =   0;
    this.startTime  =   0;
    this.LocalEndpoint  =   undefined;
    this.RemoteEndpoint =   undefined;
}
module.exports = ReqMessage;

ReqMessage.prototype.setTimeout = function(iTimeout) {
    var self = this;

    self.startTime  =   TimeProvider.nowTimestamp();
    self.timer      =   setTimeout(function() {
        self.adapter ? self.adapter.doTimeout(self) : self.worker.doTimeout(self);
    }, iTimeout);
}

ReqMessage.prototype.clearTimeout = function() {
    clearTimeout(this.timer);
    this.timer  =   undefined;
    this.costTime   =   TimeProvider.nowTimestamp - this.startTime;
}